package com.fivefu.core.hik.controller;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.dto.response.THikTaxiData;
import com.fivefu.core.hik.services.DbHikVehicleService;
import com.fivefu.core.hik.services.HikVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 海康车辆信息 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-09-01 18:02:39
 */
@Api(tags = "车辆")
@RestController
@RequestMapping("/hikvehicle")
public class DbHikVehicleController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(DbHikVehicleController.class);

    @Resource
    private HikVehicleService hikVehicleService;

    @Resource
    private DbHikVehicleService dbHikVehicleService;

    @ApiOperation(value = "查询车辆信息列表v1",httpMethod = "POST",response = ResultInfo.class,notes = "查询车辆信息列表v1")
    @RequestMapping(path = "/vehicleInformation",method = RequestMethod.POST)
    public ResultInfo vehicleInformation () {
        try {
            hikVehicleService.searchForVehicleInformation();
            return ResultInfo.renderSuccess("查询车辆信息列表v1成功");
        } catch (Exception e) {
            logger.error("查询车辆信息列表v1出现异常" + e.getMessage(),e);
            return ResultInfo.renderError("查询车辆信息列表v1失败");
        }
    }

    @ApiOperation(value = "根据车牌号码获取车辆信息(含设备)v1",httpMethod = "POST",response = ResultInfo.class,notes = "查询车辆信息列表v1")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vehicleLicensePlate",value = "车牌号码",paramType = "query",required = true,dataType = "String")
    })
    @RequestMapping(path = "/licensePlateVehicles",method = RequestMethod.POST)
    public ResultInfo licensePlateVehicles () {
        try {
            String vehicleLicensePlate = StrUtils.isCheckNull(request.getParameter("vehicleLicensePlate"));
            if (StrUtils.isNull(vehicleLicensePlate)){
                return ResultInfo.renderError("车牌号码不能为空");
            }
            hikVehicleService.vehicleInformation(vehicleLicensePlate);
            return ResultInfo.renderSuccess("查询车辆信息列表v1成功");
        } catch (Exception e) {
            logger.error("根据车牌号码获取车辆信息(含设备)v1出现异常" + e.getMessage(),e);
            return ResultInfo.renderError("根据车牌号码获取车辆信息(含设备)v1失败");
        }
    }

    @ApiOperation(value = "根据车牌号码更新车辆点位信息",httpMethod = "POST",response = ResultInfo.class,notes = "更新车辆点位信息")
    @RequestMapping(path = "/renewVehiclesShapestr",method = RequestMethod.POST)
    public ResultInfo renewVehiclesShapestr () {
        try {
            hikVehicleService.vehiclePoint();
            return ResultInfo.renderSuccess("根据车牌号码更新车辆点位信息成功");
        } catch (Exception e) {
            logger.error("根据车牌号码更新车辆点位信息异常" + e.getMessage(),e);
            return ResultInfo.renderError("根据车牌号码更新车辆点位信息失败");
        }
    }

    @ApiOperation(value = "查询出租车信息",httpMethod = "POST",response = ResultInfo.class,notes = "查询出租车信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plateNo",value = "车牌号码",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "status",value = "状态",paramType = "query",dataType = "String")

    })
    @RequestMapping(path = "/taxiData",method = RequestMethod.POST)
    public ResultInfo taxiData () {
        Map<String, String> params = formatDataToMap();
        String plateNo = params.get("plateNo");
        String status = params.get("status");
        try {
            Map taxiData = dbHikVehicleService.getTaxiData(status, plateNo);
            return ResultInfo.renderSuccess(taxiData);
        } catch (Exception e) {
            logger.error("查询出租车信息出现异常" + e.getMessage(),e);
            return ResultInfo.renderError("查询出租车信息失败");
        }
    }
}
